#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pushButton_clicked()
{
    QMessageBox* msg = new QMessageBox();
    msg->setWindowTitle("对话框");
    msg->setIcon(QMessageBox::Warning);
    msg->setText("这是一个对话框");
    msg->setStandardButtons(QMessageBox::Ok | QMessageBox::Save | QMessageBox::No);

    msg->resize(400,300);

    int rest = msg->exec();
    if(rest == QMessageBox::Ok)
        qDebug()<<"ok";
    else if(rest == QMessageBox::Save)
        qDebug()<<"save";
    else
        qDebug()<<"no";

    delete msg;
    //  msg->setAttribute(Qt::WA_DeleteOnClose);

}

void MainWindow::on_pushButton_2_clicked()
{
    int rest = QMessageBox::information(this,"自带对话框","这是一段文本",QMessageBox::Ok|QMessageBox::Cancel);
    if(rest==QMessageBox::Ok)
        qDebug()<<"ok";
    else
        qDebug()<<"cancel";
}
